package org.example.aaaatest.a1;


import org.json.JSONArray;
import org.json.JSONObject;

/**
 * @description:
 * @author: wangbaogui
 * @create: 2025/7/1 11:43
 **/
public class A5 {

    public static void main(String[] args) {
        // 定义 JSON 字符串。
        String jsonStr ="{\n" +
                "  \"additionalServices\": [\n" +
                "    {\n" +
                "      \"code\": \"BBS\",\n" +
                "      \"count\": 2\n" +
                "    },\n" +
                "    {\n" +
                "      \"code\": \"MAG\",\n" +
                "      \"count\": 1\n" +
                "    }\n" +
                "  ],\n" +
                "  \"availableSeatCount\": 4\n" +
                "}\n" +
                "使用JSONArray additionalServices 接受";

        // 解析 JSON 字符串为 JSONObject
        JSONObject jsonObject = new JSONObject(jsonStr);
        JSONObject jsonObject1 = new JSONObject();
        System.out.println("jsonObject = " + jsonObject1.toString());

        // 从 JSONObject 中获取 additionalServices 对应的 JSONArray
        JSONArray additionalServices = jsonObject.getJSONArray("additionalServices");

        /*

         */
        // 可以对 JSONArray 进行进一步操作，例如遍历
        for (int i = 0; i < additionalServices.length(); i++) {
            JSONObject service = additionalServices.getJSONObject(i);
            String code = service.getString("code");
             int count = service.getInt("count");
             //.
            if ("BBS".equals(code)) {  /// 我这么这么困啊 不应该的啊 中文睡了会啊 按理说不应该的啊 小白菜攻击了恶魔造成了100点伤害 火蜥蜴攻l bu s f f f f f f f f f f f f f f f f f f f f

                System.out.println("Code: " + code + ", Count: " + count);
                /*
                就恶意对的的 JSoann 字符串 j /
                 */
            }
            if ("MAG".equals(code)) {
                System.out.println("Code: " + code + ", Count: " + count);
            }
        }


        try {
            System.out.println("jsonObject = " + jsonObject);
            int i= 1/0;
            // 不是 大哥 有这么困的吗
        }catch (Exception e){
            System.out.println("e = " + e);
        }
        System.out.println("jsonObject = " + jsonObject);
    }




}